package com.ecy.quadratic.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ecy.quadratic.R;
import com.ecy.quadratic.adapter.CommunitySpecialAreaAdapter;
import com.ecy.quadratic.beans.CommunitySpecialArea;
import com.ecy.quadratic.ui.activity.SpecialAreaActivity;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2016/3/31.
 */
public class CommunitySpecialAreaFragment extends Fragment {

    private ListView mCommunityListView;
    private View mRootView;
    private CommunitySpecialAreaAdapter mAdapter;
    private List<CommunitySpecialArea> mNovelList;


    public CommunitySpecialAreaFragment() {

        mNovelList = new ArrayList<CommunitySpecialArea>();
        CommunitySpecialArea area = new CommunitySpecialArea();
        area.setId("cp");
        area.setTitle("CP交友");
        area.setDes("求眼熟，求搅基，求CP!");
        area.setImgResId(R.drawable.special_cp);
        area.setBackgroundColor(0xffdbfedd);
        area.setImg("http://img0.u17i.com/10/06/4240/wp/5131_1276619192_FzzJwPW0DX2f.3a006_50.jpg");
        mNovelList.add(area);
        CommunitySpecialArea area2 = new CommunitySpecialArea();
        area2.setId("comic");
        area2.setTitle("漫画");
        area2.setDes("授权漫画有100元奖励!");
        area2.setImgResId(R.drawable.special_comic);
        area2.setBackgroundColor(0xfffcdeeb);
        area2.setImg("http://img2.imgtn.bdimg.com/it/u=812138972,3998046532&fm=23&gp=0.jpg");
        mNovelList.add(area2);
        CommunitySpecialArea area3 = new CommunitySpecialArea();
        area3.setId("cos");
        area3.setTitle("COS");
        area3.setImgResId(R.drawable.special_cos);
        area3.setDes("欢迎COSPLAY同好，打破次元墙~!!!");
        area3.setBackgroundColor(0xffe9defc);
        area3.setImg("http://img3.imgtn.bdimg.com/it/u=515765522,418236175&fm=23&gp=0.jpg");
        mNovelList.add(area3);
        CommunitySpecialArea area4 = new CommunitySpecialArea();
        area4.setId("beauty");
        area4.setTitle("动漫美图");
        area4.setImgResId(R.drawable.special_beauty);
        area4.setDes("做优秀美图搬运工，搬砖啦上路啦");
        area4.setBackgroundColor(0xffdefcfc);
        area4.setImg("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3708147988,4053567601&fm=11&gp=0.jpg");
        mNovelList.add(area4);
        CommunitySpecialArea area5 = new CommunitySpecialArea();
        area5.setId("share");
        area5.setTitle("资源共享");
        area5.setImgResId(R.drawable.special_share);
        area5.setDes("不要污，不要啊，不要啊...");
        area5.setBackgroundColor(0xfff0f8f8);
        area5.setImg("http://img0.imgtn.bdimg.com/it/u=588688756,37876964&fm=23&gp=0.jpg");
        mNovelList.add(area5);
        CommunitySpecialArea area6 = new CommunitySpecialArea();
        area6.setId("common");
        area6.setTitle("日常");
        area6.setDes("少年少女们，快来啊快来啊");
        area6.setBackgroundColor(0xfff1f4ef);
        area6.setImgResId(R.drawable.special_daily);
        area6.setImg("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1496379801222&di=aa8aaa4538a835fbc736dd65435c24c9&imgtype=0&src=http%3A%2F%2Fpic.qiantucdn.com%2F58pic%2F17%2F94%2F09%2F76b58PICr5M_1024.jpg");
        mNovelList.add(area6);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return initView(inflater, container);
    }

    private View initView(LayoutInflater inflater, ViewGroup container) {
        if (mRootView != null) {
            ViewGroup parent = (ViewGroup) mRootView.getParent();
            if (parent != null) {
                parent.removeView(mRootView);
            }
            return mRootView;
        }
        mRootView = inflater.inflate(R.layout.fragment_community_specialarea, null);
        mCommunityListView = (ListView) mRootView.findViewById(R.id.community_specialarea_listview);
        mCommunityListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SpecialAreaActivity.startActivity(getContext(), mNovelList.get(position));
            }
        });
        mAdapter = new CommunitySpecialAreaAdapter(getActivity(), mNovelList);
        mCommunityListView.setAdapter(mAdapter);
        return mRootView;
    }
}
